/*
 * To change este template, choose Tools | Templates
 * and open the template in the editor.
 */
package business.services;

import java.util.Comparator;
import model.Milestone;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author jmoura
 */
public class ComparatorMilestoneSorter implements Comparator {

    private static final Log log = LogFactory.getLog(ComparatorMilestoneSorter.class);
    private final int sortCriteria;

    /*
     * sortCriteria:
     * 0 = name
     * 1 = date start
     * 2 = start date
     * else = Code
     */
    public ComparatorMilestoneSorter(int sortBy) {
        this.sortCriteria = sortBy;
    }

    @Override
    public int compare(Object a, Object b) {
        return compareToByCriteria((Milestone) a, (Milestone) b);
    }

    private int compareToByCriteria(Milestone one, Milestone other) {
        if (sortCriteria == 0) {
            //name
            return compareToByName(one, other);
        } else if (sortCriteria == 1) {
            //default order
            return compareToByDefaultOrder(one, other);
        } else {
            //default
            return one.compareTo(other);
        }
    }

    private int compareToByDefaultOrder(Milestone one, Milestone other) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private int compareToByName(Milestone one, Milestone other) {
        return one.getName().compareToIgnoreCase(other.getName());
    }
}
